{{- if .Values.global.modules.publicDomainTemplate }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: argocd
  namespace: d8-{{ .Chart.Name }}
  {{- include "helm_lib_module_labels" (list . (dict "app" "argocd-server")) | nindent 2 }}
  annotations:
    web.deckhouse.io/export-name: "Argo CD"
    web.deckhouse.io/export-icon: "/public/img/argocd.svg"
  {{- if (include "helm_lib_module_https_ingress_tls_enabled" .) }}
    nginx.ingress.kubernetes.io/backend-protocol: HTTPS
    # Suggestions from Argo CD
    # https://argo-cd.readthedocs.io/en/stable/operator-manual/ingress/#ssl-passthrough-with-cert-manager-and-lets-encrypt
    nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
    nginx.ingress.kubernetes.io/ssl-passthrough: "true"
  {{- end }}
spec:
  ingressClassName: {{ include "helm_lib_module_ingress_class" . | quote }}
  {{- if (include "helm_lib_module_https_ingress_tls_enabled" .) }}
  tls:
  - hosts:
    - {{ include "helm_lib_module_public_domain" (list . "argocd") }}
    secretName: {{ include "helm_lib_module_https_secret_name" (list . "ingress-tls-argocd") }}
  {{- end }}
  rules:
  - host: {{ include "helm_lib_module_public_domain" (list . "argocd") }}
    http:
      paths:
      - path: /
        pathType: ImplementationSpecific
        backend:
          service:
            name: argocd-server
            port:
              name: http
              # name: https
  {{- if eq (include "helm_lib_module_https_mode" .) "CertManager" }}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: argocd
  namespace: d8-{{ .Chart.Name }}
  {{- include "helm_lib_module_labels" (list . (dict "app" "argocd-server")) | nindent 2 }}
spec:
  certificateOwnerRef: false
  secretName: {{ include "helm_lib_module_https_secret_name" (list . "ingress-tls-argocd") }}
  {{ include "helm_lib_module_generate_common_name" (list . "argocd") | nindent 2 }}
  dnsNames:
  - {{ include "helm_lib_module_public_domain" (list . "argocd") }}
  issuerRef:
    name: {{ include "helm_lib_module_https_cert_manager_cluster_issuer_name" . }}
    kind: ClusterIssuer
  {{- end }}
{{- end }}
